<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of m_dangki
 *
 * @author Tuyet
 */
class m_dangky extends CI_Model{
    //put your code here
    private $_table = "nguoidung";
    function __construct() {
        parent::__construct();
        $this->load->database();
    }
    function getalldata(){
        $this->db->select('*');
        $this->db->from('nguoidung');
        $this->db->order_by('MaNguoiDung','asc');
        $query = $this->db->get();
        $data= $query->result_array();
        return $data;
    }
    function getInfo($id){
        $this->db->where("MaNguoiDung",$id);
        $query = $this->db->get($this->_table);
        
        if($query)
            return $query->row_array();
        else
            return FALSE;
    }
    function Laythongtinquaemail($fgemail){
        $this->db->select('*');
        $this->db->where("Email",$fgemail);
        $query = $this->db->get("nguoidung");
        $data= $query->result();
        return $data;
    }
    
    //--- Them User moi
    function addUser($data){
       if( $this->db->insert("nguoidung",$data))
        //if($this->db->insert($this->_table,$data))
            return TRUE;
        else
            return FALSE;
    }

    //--- Xoa user
    function deleteUser($id){
        if($id!=1){
            $this->db->where("MaNguoiDung",$id);
            $this->db->delete($this->_table);
        }
    }

    //--- Cap nhat user
    function updateUser($data,$id){
         $this->db->select('*');
        $this->db->where("MaNguoiDung",$id);
        if($this->db->update('nguoidung',$data))
            return TRUE;
        else
            return FALSE;
    }
     //---- Kiem tra username hop le
    function getUser($username,$id){
        if(isset($id)){ //use for update
           $this->db->where("TenDangNhap",$username);
           $this->db->where("MaNguoiDung !=",$id);
           $query = $this->db->get($this->_table);
        }
        else{ //user for add
            $this->db->where("TenDangNhap",$username);
            $query = $this->db->get($this->_table);
        }
        
        if($query->num_rows()!=0){
            return FALSE;
        }
        else{
            return TRUE;
        }
    }


}

?>
